//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//

//
#ifndef Green_VectorLayoutSetupGPGPU_H
#define Green_VectorLayoutSetupGPGPU_H

#include "VectorLayout.h"

namespace Green {

  class RegisterFile;
  class VectorRegisterOperandStructure;

  /*!
    \class VectorLayoutSetupGPGPU
    \brief Class for configuring VectorLayout objects.
  */
  class VectorLayoutSetupGPGPU {
  public:
    explicit VectorLayoutSetupGPGPU(const RegisterFile* pRegFile);
    COPY_CONSTRUCTOR_ABSENT(VectorLayoutSetupGPGPU);
    DESTRUCTOR_DEFAULT(VectorLayoutSetupGPGPU);
    ASSIGNMENT_OPERATOR_ABSENT(VectorLayoutSetupGPGPU);

    void SetUpVectorLayoutVtype(const VectorRegisterOperandStructure& rVecRegOprStruct, VectorLayout& rVecLayout) const; //!< Configure the VectorLayout object using current vtype register values.
    void SetUpVectorLayoutFixedElementSize(const VectorRegisterOperandStructure& rVecRegOprStruct, VectorLayout& rVecLayout) const; //!< Configure the VectorLayout object using vtype register values, but with the element width specified by the operand.
    void SetUpVectorLayoutWholeRegister(const VectorRegisterOperandStructure& rVecRegOprStruct, VectorLayout& rVecLayout) const; //!< Configure the VectorLayout object for a whole register instruction.
    uint32 GetSew() const; //!< Get the current SEW value.
    float GetLmul() const; //!< Get the current LMUL value.
  private:
    void SetUpVectorLayoutWithLayoutMultiple(const VectorRegisterOperandStructure& rVecRegOprStruct, const float layoutMultiple, VectorLayout& rVecLayout) const; //!< Configure the VectorLayout object using current vtype register values adjusted by a multiple.
    uint32 GetVl() const; //!< Get the current VL value.
    void AdjustForLimits(VectorLayout& rVecLayout) const; //!< Adjust VectorLayout values to lie within architectural limits. Mark the VectorLayout as illegal if the unadjusted values exceeded the limits.
  private:
    const RegisterFile* mpRegFile; //!< Register file
  };

}

#endif  // Green_VectorLayoutSetupGPGPU_H
